package cn.xgxd.web;

import cn.xgxd.pojo.Forum;
import cn.xgxd.result.Result;
import cn.xgxd.service.ForumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@CrossOrigin
@RequestMapping("/forum")
public class ForumController {
    @Autowired
    private ForumService forumService;

    @GetMapping
    public Result findAllpost(@RequestParam(required = false ,defaultValue = "1") Integer page){
        return Result.success(  forumService.findAllpost(page));
    }

    @PostMapping
    public  Result insert(@RequestBody Forum forum){
        forumService.insertForum(forum);
        return Result.success();
    }

    @GetMapping("/user/{id}")
    public Result findUserById(@PathVariable("id")  String id){
        return Result.success(  forumService.findUserById(id));
    }
    @GetMapping("/count")
    public Result selectForumCount(){
        return Result.success(forumService.selectForunCount());
    }
}
